//
//  LMNavigtionController.swift
//  WeiBo
//
//  Created by Li MAc on 2018/11/13.
//  Copyright © 2018 Li MAc. All rights reserved.
//

import UIKit

class LMNavigtionController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

    //隐藏 navigationBar
        navigationBar.isHidden = true
    }

    
    //重写 push 方法，所有的 push 动作都会调用此方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //不是栈低控制器才需要隐藏，栈低控制器具有多个子控制器
        if children.count > 0 {
           
            viewController.hidesBottomBarWhenPushed = true
            
        }
        
        //判断控制器的类型
        if let vc = viewController as? LMBaseViewController{
            
            //判断控制器的级数，当只有一个控制器的时候，显示栈底控制器的标题的
            if children.count  == 1 {
                title = children.first?.title ?? "返回"
                // vc 的 navigationBar 是自定义的
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: "返回", fotSize: 16, target: self, action: #selector(popViewFun) , isBack:true)
            }
           
        
        }
        super.pushViewController(viewController, animated: true)
    }

    
    @objc private func popViewFun(){
        
        popViewController(animated: true)
    }

}
